import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

ParaCalSubItem {
    id: root
    title: qsTr("零点校准")
    width: 784
    height: 338
    property color btnColor: "#7080C0"
    property bool zeroCalOK: false
    onSignalPre: {
    }
    onSignalNext: {
    }
    onSignalOK: {
        if(paraCalLoader.visible){
            return
        }
        //normalSettingSaveOK=false;
        paraCalLoader.visible=true
        var result = mymodbus.zeroCalibration();
        paraCalLoader.visible=false
        if(result){
            //normalSettingSaveOK=true;

            paraCalView.signalSuccess()
            //normalParaSaveOKDialog.open()
//            normalParaSaveOKDialog.accepted.connect(function() {
//                                    normalParaSaveOKDialog.close()
//                                })
        }
        else
        {
            paraCalView.signalFailed()
//            normalParaSaveOKDialog.open()
//            normalParaSaveOKDialog.accepted.connect(function() {
//                                    normalParaSaveOKDialog.close();
//                                })
        }
    }
    Component.onCompleted: {
        deviceTimer.interval = mymodbus.collectTime
        deviceTimer.running = true;
    }
    Component.onDestruction:
    {
        deviceTimer.running = false;
        deviceTimer.destroy();
    }
    Rectangle
    {
        width:800
        height: 150
        color:"transparent"
        GridLayout{ //root中放置一个行布局，布局中放置3个方块
            id: zeroCalibrationLayout
            anchors.centerIn: parent
            //rowSpacing: 10 //间距
            rows: 3//行数
            columns: 1 //列数

//            Rectangle {
//                id: recCurrentValue
////                width:180
////                height:30
//                // x: 218
//                // y: 7
//                color: "transparent"
//                border.width: 0
//                border.color: "white"
//                Layout.row:0
//                Layout.column:0
//                //Layout.preferredWidth: 180
//                Layout.preferredHeight: 30
//                TextInput{
//                    id:currentValue
//                    anchors.fill: parent
//                    //text:qsTr("电压:")+mymodbus.current0.toString()+"mV"
//                    //echoMode: TextInput.Password
//                    color:"white"
//                    font.pixelSize: 20
//                    horizontalAlignment: Text.AlignHCenter
//                    verticalAlignment: Text.AlignBottom
//                    readOnly: true
//                    MouseArea {
//                           anchors.fill: parent
//                           onClicked: {
//                               // miniKeyBoard.lineValue = "";
//                               // miniKeyBoard.textInput=oldPwd;
//                           }
//                       }

//                }
//            }
            Text{
                id:currentValue
                Layout.row:0
                Layout.column:0
                Layout.preferredHeight: 30
                Layout.alignment: Qt.AlignHCenter  // 使用Layout.alignment替代anchors.horizontalCenter
                //anchors.horizontalCenter: parent.horizontalCenter
                //anchors.fill: parent
                //text:qsTr("电压:")+mymodbus.current0.toString()+"mV"
                //echoMode: TextInput.Password
                color:"white"
                font.pixelSize: 20
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignBottom

            }
            Rectangle {
                    id:stableLight
                    Layout.row:1
                    Layout.column:0
                    Layout.preferredWidth: 30
                    Layout.preferredHeight: 30
                    Layout.alignment: Qt.AlignHCenter  // 使用Layout.alignment替代anchors.horizontalCenter
                    z:100
                    //anchors.horizontalCenter: parent.horizontalCenter
                    //y: 125;                  // 位于父窗体的y位置，以左上角为起点，缺省为0
                    //width: 30;            // 宽度，此时Rectangle控件在Window控件内，属于Window的孩子，可以使用parent继承
                    //height: 30;           // 高度，此时Rectangle控件在Window控件内，属于Window的孩子，可以使用parent
                    color: "transparent";         // 颜色，缺省为白色
                    opacity: 1;          // 透明度，缺省为1
                    radius: 15;           // 圆角，通过圆角来画出一个圆形窗体出来
                    clip: true;            // 截断，在Rectangle控件内的子控件，超出他本身大小后会被截断
                }
            Text{
                id:zeroCalTip
                Layout.row:2
                Layout.column:0
                Layout.preferredHeight: 60
                Layout.alignment: Qt.AlignHCenter  // 使用Layout.alignment替代anchors.horizontalCenter
                //anchors.horizontalCenter: parent.horizontalCenter
                //anchors.fill: parent
                text:qsTr("请先清空称台，指示灯变绿后")+"\n"+qsTr("点击“确认”，完成零点标定")
                //wrapMode: Text.Wrap
                color:"white"
                font.pixelSize: 20
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignBottom

            }
        }

   }
    MyBuzyIndicator{
        anchors.centerIn: parent
        id: zeroCalLoader
        visible:false
    }
    Dialog {
        anchors.centerIn: parent
        closePolicy: "CloseOnEscape"
        modal:true
        id: zeroCalPanelDialog
        standardButtons: Dialog.Ok
//        onAccepted: {
//            zeroCalPanelDialog.close()
//            if(zeroCalOK){
//                bottomBar.selected=0
//                //myLoader.setsource="StatusView.qml"
//                myLoader.visible=false;
//                statusView.visible=true;
//            }
//        }
        z:100
    }
    Timer{
        id:deviceTimer
        //interval: mymodbus.collectTime
        running: false
        repeat: true
        onTriggered: {
            currentValue.text = qsTr("电压:")+mymodbus.voltage+"uV"
            stableLight.color = mymodbus.stable===1? "green":"red";
        }

    }
}
